/*********************************************************************************
  *FileName:  nsuc16xx_systick.c
  *Version:  V1.0
  *Date: 2023-04-19
****************************************Includes***********************************/
#include "nsuc16xx_systick.h"


/***************************************Variables***********************************/



/***************************************Functions***********************************/
void SysTick_Init(SysTick_InitTypeDef *SysTick_InitStruct)
{
    SysTick->VAL = SysTick_InitStruct->SysTick_CurrentValue;
    SysTick->LOAD = SysTick_InitStruct->SysTick_ReLoadValue;

    if (SysTick_InitStruct->SysTick_CoclkSource == Systick_CoclkSource_STCLK)
    {
        SysTick->CTRL &= (~SysTick_CTRL_CLKSOURCE_Msk);
    }
    else
    {
        SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
    }
}

void SysTick_ITConfig(FunctionalState NewState)
{
    if (NewState != DISABLE)
    {
        SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
    }
    else
    {
        SysTick->CTRL &= (~SysTick_CTRL_TICKINT_Msk);
    }
}

void SysTick_CounterCmd(FunctionalState NewState)
{
    if (NewState != DISABLE)
    {
        SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
    }
    else
    {
        SysTick->CTRL &= (~SysTick_CTRL_ENABLE_Msk);
    }
}

uint32_t SysTick_GetCount(void)
{
    uint32_t count = SysTick->VAL;
    return count;
}

void SysTick_SetReload(uint32_t ReLoadValue)
{
    SysTick->LOAD = ReLoadValue;
}

uint32_t SysTick_GetReload(void)
{
    uint32_t count = SysTick->LOAD;
    return count;
}

/***************************************END OF FILE*********************************/
